import java.util.ArrayList;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: nn
 * Date: 2024-07-30
 * Time: 21:02
 * <T>占位符,当前类是一个泛型类
 */
class MyArray<T> {
    //public Object[] array = new Object[10];
    //public T[] array = new T[10];

    //public T[] array = (T[])new Object[10];

    public Object[] array = new Object[10];
    public void setValue(int pos,T val) {
        array[pos] = val;
    }

    public T getValue(int pos) {
        return (T) array[pos];
    }

}


class Person {

}
public class Test {
    public static void main6(String[] args) {
        MyArray<String> myArray = new MyArray<>();

    }
    public static void main5(String[] args) {
        MyArray<String> myArray = new MyArray<>();

        //裸类型
        MyArray myArray2 = new MyArray();
        myArray2.setValue(0,1);

    }
    //目的：想存放指定的元素
    public static void main4(String[] args) {
        MyArray<String> myArray = new MyArray<>();
        myArray.setValue(0,"hello");
        myArray.setValue(1,"word");
        myArray.setValue(2,"text");

        String str = myArray.getValue(2);
        System.out.println(str);

        MyArray<Integer> myArray2 = new MyArray<>();
        myArray2.setValue(0,99);
        myArray2.setValue(1,20);
        int val = myArray2.getValue(0);
        System.out.println(val);

        MyArray<Person> myArray3 = new MyArray<>();

    }
    public static void main(String[] args) {
        Integer ii1 = 100;
        Integer ii2 = 100;
        Integer ii3 = 200;
        Integer ii4 = 200;
        System.out.println(ii1 == ii2);
        System.out.println("--------");
        System.out.println(ii3 == ii4);//flase是因为Integer的范围是[-128,127]
    }

    public static void main2(String[] args) {
        int a = 10;
        //Integer ii = a;//自动装箱
        Integer ii = Integer.valueOf(a);//手动装箱


        Integer ii2 = new Integer(10);
        //int b = ii2;//自动拆箱
        int b = ii2.intValue();//手动拆箱
        double d = ii2.doubleValue();



        System.out.println(ii);
        System.out.println(b);
        System.out.println(d);
    }
    public static void main1(String[] args) {
        int a = 10;
        Integer ii = a;//自动装箱

        Integer ii2 = new Integer(10);
        int b = ii2;//自动拆箱


        System.out.println(ii);
        System.out.println(b);
    }
}
